package com.qunar.flight.myserver;

import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

import org.apache.log4j.Logger;

public class Server1 {
	static Logger logger=Logger.getLogger(Server1.class);

	public static void main(String[]args){
		try {
			Selector sel=Selector.open();
			
			ServerSocketChannel ssc=ServerSocketChannel.open();
			ssc.socket().setReuseAddress(true);
			ssc.socket().bind(new InetSocketAddress(8080));
			ssc.configureBlocking(false);
			
			Dispatcher d = new Dispatcher1(sel);	
			d.register(ssc, SelectionKey.OP_ACCEPT, new AcceptHandler(ssc,d));
			new Thread(d).start();
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
		}
	}
}
